# -*- coding=utf-8
import json
import urllib.request
import sys

TalkApi = "https://oapi.dingtalk.com/robot/send?access_token=021ea648e8f8d849125ae9bd7590016acde2e239dc2eb4b83b366c4c3289e0a7"

def ToDingTalk(new_text):
    try:
        header = {
            "Content-Type": "application/json",
            "Charset": "UTF-8"
        }

        data = {
            "msgtype": "text",
            "text": {
                "content": new_text
            }
        }

        sendData = json.dumps(data)
        sendData = sendData.encode("utf-8")
        request = urllib.request.Request(url=TalkApi, data=sendData, headers=header)
        opener = urllib.request.urlopen(request)

    except Exception:
	    print("发送信息至钉钉服务器失败！")

    else:
	    print("发送信息至钉钉服务器成功！")